// pages/myself/order/shouhou/wuliu.js
var Zan = require('../../../../dist/index');
var network = require('../../../../utils/network_util.js');
var api = require('../../../../utils/api.js');
var app = getApp();
Page(Object.assign({}, Zan.TopTips,{

  /**
   * 页面的初始数据
   */
  data: {
    refundOrderId: null,
    region: [
      '顺丰快递',
      'EMS',
      '申通快递',
      '圆通快递',
      '中通快递',
      '汇通快递',
      '天天快递',
      '韵达快递',
      '全峰快递',
      '中国邮政',
      '邮政平邮',
      '港中能达',
      '宅急送快递',
      '德邦物流',
    ],
    index: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      refundOrderId: options.refundOrderId
    })
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },
  //快递选择监听
  bindRegionChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
  //退货物流信息提交
  formSubmit: function (e) {
    var expressNo = e.detail.value.expressNo;
    var reg = new RegExp("^[0-9a-zA-Z]*$");
    if (reg.test(expressNo) && expressNo) {
      var postdata = {
        refundOrderId: this.data.refundOrderId,
        expressName: this.data.region[this.data.index],
        expressNo: e.detail.value.expressNo

      }
      network._post_json(this, api.orderReturnEx, postdata, formSuccess);
    } else {
      wx.showModal({
        title: '提示',
        content: '物流单号不合法',
      })
    }

  }
}))

var formSuccess = function (that, res) {
  if (res.data.status == 1) {
    setTimeout(function () {
      wx.showToast({
        title: '已经提交',
      })

    }, 1000)
    var pages = getCurrentPages();
    if (pages.length > 1) {
      //上一个页面实例对象
      var prePage = pages[pages.length - 2];
      if (prePage.refresh && typeof (prePage.refresh) == "function") {
        prePage.refresh(false);
      }
    }
    wx.navigateBack({

    })
  }
}